<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>JS原生绑定事件--dom2级事件绑定</h2>
    <div class="box1">
        11111
        <div class="box2">22222
            <div class="box3">

                33333

                <button class="btn">绑定事件</button>
            </div>
        </div>

    </div>
</body>
<script>
    //获取dom
    const btn = document.querySelector('.btn')
    const box33 = document.querySelector('.box3')
    const box22 = document.querySelector('.box2')
    const box11 = document.querySelector('.box1')

    //给btn绑定事件
    // btn.onclick = aa;
    // btn.onclick = bb;

    // btn.addEventListener('事件名',事件方法,冒泡/捕获)
    btn.addEventListener('click', aa, false)
    box33.addEventListener('click', box3, false)
    box22.addEventListener('click', box2, false)
    box11.addEventListener('click', box1, false)
        // btn.addEventListener('click', bb, false)

    function aa(e) {
        //阻止冒泡 
        //  e.stopPropagation();

        console.log('我是aa函数')

        //移除box1上的事件
        box11.removeEventListener('click', box1)


    }

    function bb() {
        console.log('我是bb函数')
    }

    function box3() {
        console.log('我是box3函数')
    }

    function box2() {
        console.log('我是box2函数')
    }

    function box1() {
        console.log('我是box1函数')
    }
</script>

</html>